package com.hc.cesium.Handler;

import com.hc.cesium.model.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AdminInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
       try{
           User user = (User) request.getSession().getAttribute("user");
           if (user!=null){
               return true;
           }
           response.sendRedirect(request.getContextPath()+"/login");
       }catch (Exception e){
                e.printStackTrace();
       }
        return false;
    }
}
